package com.budwk.app.miniapp.controllers.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

import com.budwk.app.miniapp.models.SqfwNotice;
import com.budwk.app.miniapp.models.WxUser;
import com.budwk.app.miniapp.services.SqfwNoticeService;
import com.budwk.app.miniapp.services.WxUserAuthService;
import com.budwk.app.miniapp.services.WxUserService;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysDictService;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.starter.common.exception.BaseException;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.security.utils.SecurityUtil;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.nutz.dao.Cnd;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;

import java.util.Date;

@IocBean
@At("/platform/sqfw/sqfwNotice")
@ApiDefinition(tag = "公告")
@Slf4j
public class SqfwNoticeController {



    @Inject
    private WxUserService wxUserService;
    @Inject
    private SysDictService sysDictService;

    @Inject
    private SqfwNoticeService sqfwNoticeService;




    @At
    @Ok("json")
    @POST
    public Result<?> getlistPage(@RequestBody SqfwNotice sqfwNotice) {
        Cnd cnd = Cnd.NEW();
        if(StrUtil.isNotBlank(sqfwNotice.getCity())&&!sqfwNotice.getCity().equals("直属")){
            SqlExpressionGroup e1 = Cnd.exps(SqfwNotice::getCity,"=",sqfwNotice.getCity());
            cnd.and(e1);
        }
        if(StrUtil.isNotBlank(sqfwNotice.getCounty())&&!sqfwNotice.getCounty().equals("直属")){
            SqlExpressionGroup e1 = Cnd.exps(SqfwNotice::getCounty,"=",sqfwNotice.getCounty());
            cnd.and(e1);
        }
        if(StrUtil.isNotBlank(sqfwNotice.getCommunity())&&!sqfwNotice.getCommunity().equals("直属")){
            SqlExpressionGroup e1 = Cnd.exps(SqfwNotice::getCommunity,"=",sqfwNotice.getCommunity());
            cnd.and(e1);
        }
        cnd.orderBy(SqfwNotice::getCreateTime,sqfwNotice.getSort());
        Pagination getListPage=sqfwNoticeService.listPage(sqfwNotice.getPageNo(),sqfwNotice.getPageSize(),cnd);
        return Result.success(getListPage);
    }

    @At("/getOneInfo")
    @Ok("json")
    @POST
    public Result<?> getOneInfo(@RequestBody SqfwNotice sqfwNotice) {
        if(ObjectUtil.isEmpty(sqfwNotice.getNoticeId())){
            throw new BaseException("noticeId不能为空");
        }
        SqfwNotice  sqfwNoticeInfo=   sqfwNoticeService.fetch(sqfwNotice.getNoticeId());
        return Result.success(sqfwNoticeInfo);
    }
}
